// 拷贝文件的程序
// 操作失败 Permission denied
#include <stdio.h>
int main(void){
	char inName[64], outName[64];
	FILE *in, *out;
	int c;
	
	// 从使用者得到文件名
	printf("Enter name of file to be copied: ");
	scanf("%63s", inName);
	printf("Enter name of output file: ");
	scanf("%63s", outName);
	
	// 打开输入输出文件
	if((in = fopen(inName, "r")) == NULL){
		printf("Can't open %s for reading.\n", inName);
		return 1;
	}
	if((out = fopen(outName, "w")) == NULL){
		printf("Can't open %s for writing.\n", outName);
		return 2;
	}
	
	// 复制 in 到 out
	while((c = getc(in)) != EOF)
		putc(c, out);
	
	// 关闭打开的文件
	fclose(in);
	fclose(out);
	
	printf("File has been copied.\n");
	return 0;
}
